import java.util.Stack;

/**
 * Created by LI on 2020/7/7.
 */

public class Lyl {

    public static void main(String[] args) {
        MyQueue queue = new MyQueue();
        System.out.println("empty:" + queue.empty());
        queue.push(1);
        queue.push(2);
        System.out.println("pop:" + queue.pop());
        System.out.println("pop:" + queue.pop());
        System.out.println("empty:" + queue.empty() + "-----size:" + queue.size());
        queue.push(1);
        queue.push(2);
        System.out.println("peek:" + queue.peek());
        System.out.println("pop:" + queue.pop());
        System.out.println("peek:" + queue.peek());
    }

    private static class MyQueue {
        private Stack<Integer> pushStack = new Stack<>();
        private Stack<Integer> popStack = new Stack<>();

        private void push(int node) {
            pushStack.push(node);
        }

        private int pop() {
            peek();
            return popStack.pop();
        }

        private boolean empty() {
            return pushStack.empty() & popStack.empty();
        }


        private int peek() {
            if (!popStack.isEmpty()) {
                return popStack.peek();
            }
            if (pushStack.isEmpty()) {
                throw new RuntimeException("Queue is empty");
            }
            while (!pushStack.isEmpty()) {
                popStack.push(pushStack.pop());
            }
            return popStack.peek();
        }

        private int size() {
            return popStack.size() + pushStack.size();
        }
    }
}
